<template>
  <div class="admin-add">
    <el-form :model="FormData" label-width="100px" class="demo-ruleForm">
      <el-form-item label="用户名:" prop="account">
        <el-input v-model="FormData.account"></el-input>
      </el-form-item>
      <el-form-item label="密码:" prop="password">
        <el-input v-model="FormData.password"></el-input>
      </el-form-item>
      <el-form-item label="角色:" prop="status">
        <el-select v-model="FormData.status" placeholder="请选择角色">
          <el-option label="超级管理员" value="超级管理员"></el-option>
          <el-option label="普通管理员" value="普通管理员"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">增加</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions } = createNamespacedHelpers("admin");
const {mapMutations:publicMutations} = createNamespacedHelpers("publicStore");
export default {
  data() {
    return {
      FormData: {
        account: "",
        password: "",
        status: "超级管理员",
      },
    };
  },
  created(){
    this.setNowBreadcrumb("addadmin");
  },
  methods: {
    ...mapActions(["addAdmin"]),
    ...publicMutations(["setNowBreadcrumb"]),
    async submitForm() {
      const data = await this.addAdmin(this.FormData);
      if(data.status){
          this.$message({
          message: data.msg,
          type: 'success',
        });
        this.$router.push("/system/admin/adminlist/");
      }else{
        this.$message.error(data.msg);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.admin-add {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  .demo-ruleForm {
    width: 400px;
    height: 400px;
    margin-top: 50px;
  }
}
</style>